home *** CD-ROM | disk | FTP | other *** search
/ Experimental BBS Explossion 3 / Experimental BBS Explossion III.iso / c / cp1.zip / DRIVES.C < prev    next >
C/C++ Source or Header  |  1993-04-29  |  2KB  |  69 lines

  1. ===========================================================================
  2.  BBS: The Abacus * HST/DS * Potterville, MI
  3. Date: 04-27-93 (09:14)             Number: 170
  4. From: RAY GARDNER                  Refer#: 206
  5.   To: NATE WRIGHT                   Recvd: NO  
  6. Subj: PARTITIONS                     Conf: (36) C Language
  7. ---------------------------------------------------------------------------
  8. [Nate Wright to All:]
  9.  > Hi, I was wondering if there is a way to determine the number of
  10.  > logical drives on a system?  This would include floppies, hard disk
  11.  > partitions, ram drives, swapped drives, or any other type of drive
  12.  > that can be recognized by DOS.  I've tried just fopen and a test to
  13.  > see if a file opened (I'm looking for a specific file), but that just
  14.  > produces Borland C runtime error message of Drive Not Ready.  I've
  15.  > also tried a couple of int 0x21 functions, but they don't recognize
  16.  > ram and swapped drives.  I've also tried the int 0x13 functions, but
  17.  > they only work for physical drives.  Anyone have any idea?
  18.  
  19. Here's an int 0x21 function you probably missed:
  20.  
  21. /* drives.c -- detect all valid drive letters (logical drives)
  22. **
  23. ** public domain by Ray Gardner  4/93
  24. **
  25. ** uses DOS int 21 function 29 (parse filename)
  26. ** does not activate drive, so does not get "drive not ready" status
  27. */
  28. #include <stdio.h>
  29. #include <string.h>
  30.  
  31. #include <dos.h>
  32.  
  33. int is_valid_drive(int drive_letter)
  34. {
  35.     union REGS reg;
  36.     struct SREGS segs;
  37.     char drive[4], fcb[36];
  38.  
  39.     strcpy(drive, " :");
  40.     drive[0] = drive_letter;
  41.     segread(&segs);
  42.     segs.ds = FP_SEG(drive);
  43.     reg.x.si = FP_OFF(drive);
  44.     segs.es = FP_SEG(fcb);
  45.     reg.x.di = FP_OFF(fcb);
  46.     reg.x.ax = 0x2900;
  47.     int86x(0x21, ®, ®, &segs);
  48.     return reg.h.al != 0xFF;
  49. }
  50.  
  51. int main(void)
  52. {
  53.     int i;
  54.  
  55.     printf("Valid drives are: ");
  56.     for ( i = 'a'; i <= 'z'; ++i )
  57.         if ( is_valid_drive(i) )
  58.             printf("%c ", i);
  59.         printf("\n");
  60.     return 0;
  61. }
  62.  
  63.  
  64. --- msged 1.99S ZTC
  65.  * Origin: Ray Gardner -- Englewood, CO (1:104/89.2)
  66. SEEN-BY: 1/211 11/2 4 13/13 101/1 108/89 109/25 110/69 114/5 123/19 124/1
  67. SEEN-BY: 153/752 154/40 77 157/2 159/100 125 575 950 203/23 209/209 280/1
  68. SEEN-BY: 390/1 396/1 5 15 2270/1 2440/5 3603/20
  69.